package top.yisen614.sharedelement

import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import butterknife.BindView
import butterknife.ButterKnife
import com.bumptech.glide.Glide

class DetailActivity : AppCompatActivity() {

    @BindView(R.id.detail_image)
    lateinit var detailImage: ImageView

    @BindView(R.id.detail_title)
    lateinit var titleTextView: TextView


    companion object {
        const val DETAIL_IMAGE_NAME = "detail:image"
        const val DETAIL_TEXT_NAME = "detail:text"
        const val IMAGE_URL = "image_url"
        const val IMAGE_TITLE = "image_title"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detail)

        ButterKnife.bind(this)

        //新页面接收数据
        val bundle = this.intent.extras
        //接收name值
        val url = bundle!!.getString(IMAGE_URL)
        val title = bundle.getString(IMAGE_TITLE)

        Glide.with(this).load(url).into(detailImage)
        titleTextView.text = title

        ViewCompat.setTransitionName(detailImage, DETAIL_IMAGE_NAME)

        ViewCompat.setTransitionName(titleTextView, DETAIL_TEXT_NAME)
    }
}
